                
  <?php
  // session_start();
	
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: ad-dangnhap.php");
	}
	
  include_once('luan van/connect.php');
  $data = array();
  $kq = 0;
    
  function add_person($makhoa,$tenkhoa,$matkhau)
  {
	  global $data;
	  
	  $data []= array(
		  'makhoa' => $makhoa,
		  'tenkhoa'=> $tenkhoa,
		  'matkhau' => $matkhau
		  );
	  }
  
	  if ( $_FILES['file']['tmp_name'] )
	  {
		  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
		  $rows = $dom->getElementsByTagName( 'Row' );
		  $mssv_row = true;
		  foreach ($rows as $row)
		  {
			  if ( !$mssv_row )
			  {	 
					  $index = 1;
					  $cells = $row->getElementsByTagName( 'Cell' );
					  foreach( $cells as $cell )
					  { 
						  $ind = $cell->getAttribute( 'Index' );
						  if ( $ind != null ) $index = $ind;
						  
						  if ( $index == 1 ) $makhoa = $cell->nodeValue;
						  if ( $index == 2 ) $tenkhoa = $cell->nodeValue;
						  if ( $index == 3 ) $matkhau = $cell->nodeValue;						  
						  $index += 1;
					  }
					  add_person($makhoa,$tenkhoa ,$matkhau);
			}
			$mssv_row = false;
		}
		$kq = count($data);
  	}
  ?>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Ket qua</title>
  </head>
  <body>
  <form name="form1" enctype="multipart/form-data" method="post" action="">
    <label>
      <input type="file" name="file">
    </label>
    <label>
    <input type="submit" name="Submit" value="Import">
    </label>
  </form>
  <div style="font-weight:bold; color:#FF0000; font-size:24px" align="center">
  	Kết quả import dữ liệu  </div>
  <div style="background:#00FF99; font-weight:bold; color:#FF0000">
  	<p>&nbsp;<?php echo "Da them mau tin: ".$kq; ?>
  </div>
  <?php 
  	foreach( $data as $row ) 
	{
  		mysql_query( "insert into khoa values('".$row["makhoa"]."','".$row["tenkhoa"]."','".$row["matkhau"]."')");
  	} 	
?>
  
  </body>
  </html>
